<?php
/**
 * 绩效详情,同评分页面
 */
apf_require_controller("Abstract");
apf_require_class("Bll_Jx_Relation");
apf_require_class("Bll_Jx_plan");
class Team_ShowAccessmentController extends AbstractController {

    public function handle_request() {
        $params = $this->request->get_parameters();
        $user_id = empty($params['user_id']) ? 0 :intval($params['user_id']);
        $searchdate = empty($params['searchdate']) ? 0 :intval($params['searchdate']);
        if(!$user_id){
            $this->show_tips('ERROR_PARAM');
        }
        $this->rel_bll = new Bll_Jx_Relation();
        //检测权限
        if(!$this->check_auth($user_id)){
            $this->show_tips('ERROR_AUTH');
        }
        //绩效详情
        $plan_bll = new Bll_Jx_plan();
        $baseinfo = $plan_bll->find_performance(array('userId'=>$user_id,'serachMonth'=>$searchdate));
        if(empty($baseinfo)){
            $this->show_tips('ERROR_PARAM');
        }
        $this->request->set_attribute('baseinfo', $baseinfo);
        return 'Team_ShowAccessment';
    }
    /**
     * 是主管或是HR,或是上上级主管
     */
    private function check_auth($uid){
        $user_code = $this->request->get_user_code();
        $user_id = $this->request->get_user_id();
        $hr_auth = APF::get_instance()->get_config('hr_auth');
        if(in_array($user_code,$hr_auth)){
            return true;
        }
        //直属主管
        $leader = $this->rel_bll->get_leader($user_id);
        if(!empty($leader) && $leader['superior_code'] == $user_code){
            return true;
        }
        //线主管
        $is_virtual = $this->rel_bll->get_virtual_leader($uid,$user_id);
        if($is_virtual){
            return true;
        }
        //上上级主管
        return false;
    }
}